﻿using System.Collections;
using System.Collections.Generic;

namespace Chappie.Infrastructure.DataStructure
{
    /// <summary>
    /// 分页数据结构
    /// </summary>
    public class PagedResult<T> : IEnumerable<T>
    {
        #region Fields

        private readonly IEnumerable<T> _data;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the total number of the records.
        /// </summary>
        public int? TotalRecords { get; set; }


        /// <summary>
        /// Gets or sets the total pages available.
        /// </summary>
        public int? TotalPages { get; set; }


        /// <summary>
        /// Gets or sets the number of records for each page.
        /// </summary>
        public int? PageSize { get; set; }


        /// <summary>
        /// Gets or sets the page number.
        /// </summary>
        public int? PageNumber { get; set; }


        /// <summary>
        /// Gets a list of objects contained by the current <c>PagedResult{T}</c> object.
        /// </summary>
        public IEnumerable<T> Data
        {
            get { return _data; }
        }

        #endregion

        #region Ctor

        /// <summary>
        /// 无参数初始化
        /// </summary>
        public PagedResult()
        {
            _data = new List<T>();
        }

        /// <summary>
        /// 参数初始化
        /// </summary>
        /// <param name="totalRecords"></param>
        /// <param name="totalPages"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageNumber"></param>
        /// <param name="data"></param>
        public PagedResult(int? totalRecords, int? totalPages, int? pageSize, int? pageNumber, IEnumerable<T> data)
        {
            TotalRecords = totalRecords;
            TotalPages = totalPages;
            PageSize = pageSize;
            PageNumber = pageNumber;
            _data = data;
        }

        #endregion

        #region Implementation of IEnumerable

        public IEnumerator<T> GetEnumerator()
        {
            return _data.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _data.GetEnumerator();
        }

        #endregion
    }
}